package com.witframework.baseapp.security.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.witframework.baseapp.security.BaseUser;
import com.witframework.baseapp.security.service.UserService;
import com.witframework.web.mvc.WebContext;


public class UserController {
	@Autowired
	private UserService userService;
	public String executor(WebContext webContext) {
		List<BaseUser> appList = userService.pagedQuery(webContext.getFilter(), webContext.getPageSortModel("user"));
		webContext.setAttribute("dataList", appList);			
		return "//:view/user/index.jsp";
	}

	public String edit(WebContext webContext) {
		String[] ids = webContext.getSelItemList();
		if (ids != null && ids.length > 0) {
			BaseUser app = (BaseUser) userService.get(ids[0]);
			webContext.setAttribute("data", app);			
		}
		return "//:view/user/update.jsp";
	}
	
	public String store(WebContext webContext) {
		Object app = webContext.newEntity(userService,new BaseUser());
		webContext.bindObject(app);
		webContext.validateObject("data", app, "//:view/user/update.jsp");
		userService.merge(app);		
		webContext.setPageInfo("操作成功");		
		return "redirect://this";
	}
	
	public String delete(WebContext webContext) {
		String[] ids=webContext.getSelItemList();
		userService.deleteAllByIds(ids);
		webContext.setPageInfo("成功删除"+ids.length+" 条数据");		
		return "redirect://this";
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
